<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 200px;
            height: 200px;
            background-color: pink;
        }

        .nav {
            color: red;
        }

        .box {
            width: 300px;
            height: 300px;
            background-color: skyblue;
            margin: 100px auto;
            padding: 10px;
            border: 1px solid #000;
        }
    </style>
</head>

<body>
    <div>123</div>
    <script>
        // 获取元素
        const div = document.querySelector('div')
        // 添加类名，如果元素有类名会直接替换，所以如果需要添加一个类名，可以写多个类名中间用空格隔开
        div.className = 'nav box'
    </script>
</body>

</html>